package com.lee.transactionaldemo.controller;


import com.lee.transactionaldemo.service.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author l
 * @since 2021-04-22
 */
@RestController
@RequestMapping("user")
public class UserController{

@Autowired
private TransactionService transactionService;

    @GetMapping("saveUserCallPrivate")
    public String saveUserCallPrivate(){
        transactionService.saveUserCallPrivate();
        return "OK";
    }


    @GetMapping("saveUserCallThis")
    public String saveUserCallThis(){
        transactionService.saveUserCallThis();
        return "OK";
    }


    @GetMapping("saveUserCallSelf")
    public String saveUserCallSelf(){
        transactionService.saveUserCallSelf();
        return "OK";
    }


    @GetMapping("saveUserWithTryCatch")
    public String saveUserWithTryCatch(){
        transactionService.saveUserWithTryCatch();
        return "OK";
    }

    @GetMapping("saveUserWithTryCatchRight")
    public String saveUserWithTryCatchRight(){
        transactionService.saveUserWithTryCatchRight();
        return "OK";
    }


    @GetMapping("saveUserThrowException")
    public String saveUserThrowException() throws Exception {
        transactionService.saveUserThrowException();
        return "OK";
    }

    @GetMapping("saveUserThrowExceptionRollbackFor")
    public String saveUserThrowExceptionRollbackFor() throws Exception {
        transactionService.saveUserThrowExceptionRollbackFor();
        return "OK";
    }
}
